package top.someapp;

import java.util.Hashtable;
import java.util.Map;

/**
 * @author zwz
 * Created on 2021-07-18
 */
public class ServiceLocator {

    private static final Map<Class, Object> serviceMap = new Hashtable<>();

    private ServiceLocator() {
        // no need instance.
    }

    static void register(Object object) {
        serviceMap.put(object.getClass(), object);
    }

    @SuppressWarnings("unchecked")
    public static <T> T get(Class type) {
        return serviceMap.containsKey(type) ? (T) serviceMap.get(type) : null;
    }
}
